/*
 * Copyright (c) 2006 David Pacheco
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/*
 * ctimer v0.01 
 * Simple interface for measuring the real, system, and user times elapsed
 * between two points in the program.
 * 
 * file: ctimer.h
 * desc: interface for simple C timer
 * auth: dap (dp dot spambait at gmail)
 * date: Nov 22, 2006
 */

#ifndef _CTIMER_H_

#include <time.h>
#include <sys/times.h>
#include <sys/time.h>

typedef enum { CT_INIT, CT_RUN, CT_DONE } ct_state_t;

typedef struct {
	ct_state_t ct_state;
	union {
		struct tms __ct_tm_start;
		struct tms __ct_tm_elapsed;
	} __ct_tm;
	union {
		struct timeval __ct_tv_start;
		struct timeval __ct_tv_elapsed;
	} __ct_tv;
} ctimer_t;

#define	ct_start_tm	__ct_tm.__ct_tm_start
#define	ct_elapsed_tm	__ct_tm.__ct_tm_elapsed
#define	ct_start_tv	__ct_tv.__ct_tv_start
#define	ct_elapsed_tv	__ct_tv.__ct_tv_elapsed

void ctimer_init(ctimer_t *);
void ctimer_start(ctimer_t *);
void ctimer_end(ctimer_t *);
void ctimer_print(ctimer_t *);

#endif
